﻿using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Web.Routing;

namespace jQM
{
    public static partial class HtmlHelperListExtensionMethods
    {
        public static MvcHtmlString OrderedList(this HtmlHelper helper, IEnumerable<BasicListItem> list, string theme = "g")
        {
            StringBuilder html = new StringBuilder(string.Format("<ol data-role=\"{0}\" data-theme=\"{1}\">", "listview", theme));
            html.Append(buildList(list));
            return endOrderedList(html);
        }

        public static MvcHtmlString OrderedListWithSearchFilter(this HtmlHelper helper, IEnumerable<BasicListItem> list, string searchBarPlaceholder = "Search this list", string theme = "g")
        {
            StringBuilder html = new StringBuilder(string.Format("<ol data-role=\"{0}\" data-theme=\"{1}\" data-filter=\"{2}\" data-filter-placeholder=\"{3}\">", "listview", theme, "true", searchBarPlaceholder));
            html.Append(buildList(list));
            return endOrderedList(html);
        }

        public static MvcHtmlString OrderedLinkedList(this HtmlHelper helper, IEnumerable<BasicLinkedListItem> list, string theme = "g")
        {
            StringBuilder html = new StringBuilder(string.Format("<ol data-role=\"{0}\" data-theme=\"{1}\">", "listview", theme));
            html.Append(buildLinkedList(list));
            return endOrderedList(html);
        }

        public static MvcHtmlString OrderedLinkedListWithSearchFilter(this HtmlHelper helper, IEnumerable<BasicLinkedListItem> list, string searchBarPlaceholder = "Search this list", string theme = "g")
        {
            StringBuilder html = new StringBuilder(string.Format("<ol data-role=\"{0}\" data-theme=\"{1}\" data-filter=\"{2}\" data-filter-placeholder=\"{3}\">", "listview", theme, "true", searchBarPlaceholder));
            html.Append(buildLinkedList(list));
            return endOrderedList(html);
        }

        public static MvcHtmlString OrderedGroupedList(this HtmlHelper helper, IEnumerable<Group<BasicListItem>> groupedlist, string theme = "g")
        {
            StringBuilder html = new StringBuilder(string.Format("<ol data-role=\"{0}\" data-theme=\"{1}\">", "listview", theme));
            html.Append(buildGroupedList(groupedlist));
            return endOrderedList(html);
        }

        public static MvcHtmlString OrderedGroupedListWithSearchFilter(this HtmlHelper helper, IEnumerable<Group<BasicListItem>> groupedlist, string searchBarPlaceholder = "Search this list", string theme = "g")
        {
            StringBuilder html = new StringBuilder(string.Format("<ol data-role=\"{0}\" data-theme=\"{1}\" data-filter=\"{2}\" data-filter-placeholder=\"{3}\">", "listview", theme, "true", searchBarPlaceholder));
            html.Append(buildGroupedList(groupedlist));
            return endOrderedList(html);
        }

        public static MvcHtmlString OrderedGroupedLinkedList(this HtmlHelper helper, IEnumerable<Group<BasicLinkedListItem>> groupedlist, string theme = "g")
        {
            StringBuilder html = new StringBuilder(string.Format("<ol data-role=\"{0}\" data-theme=\"{1}\">", "listview", theme));
            html.Append(buildGroupedLinkedList(groupedlist));
            return endOrderedList(html);
        }

        public static MvcHtmlString OrderedGroupedLinkedListWithSearchFilter(this HtmlHelper helper, IEnumerable<Group<BasicLinkedListItem>> groupedlist, string searchBarPlaceholder = "Search this list", string theme = "g")
        {
            StringBuilder html = new StringBuilder(string.Format("<ol data-role=\"{0}\" data-theme=\"{1}\" data-filter=\"{2}\" data-filter-placeholder=\"{3}\">", "listview", theme, "true", searchBarPlaceholder));
            html.Append(buildGroupedLinkedList(groupedlist));
            return endOrderedList(html);
        }

        private static MvcHtmlString endOrderedList(StringBuilder html)
        {
            html.Append("</ol>");
            return MvcHtmlString.Create(html.ToString());
        }
    }
}